/******************************************************************************
 * Copyright (C) 2017 Chengdu Dlhd information industry co. LTD.
 * All Rights Reserved.
 * 本软件为成都顶联互动信息产业有限公司开发研制。未经本公司正式书面同意，其他任何个人、团体不得使用、复制、修改或发布本软件.
 *****************************************************************************/
package  net.dgg.dggcloud.service.jrcrm.common.tag;


import net.dgg.dggcloud.core.constants.Constants;
import net.dgg.dggcloud.service.entity.OperationRight;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;
import java.util.List;

/**
 * @ClassName 〈SystemRightTag>
 * @Description
 * @Author 朱永波
 * @Date 2017/11/10 9:18
 */
public class SystemRightTag extends TagSupport {
    /**
     * 权限的code
     */
    private String code;

    @Override
    public int doStartTag() throws JspException {
        try {
            Object rights = pageContext.getSession().getAttribute(Constants.USER_RIGHTS_SESSION_KEY);
            if(null != rights){
                List pageRights = (List) rights;
                for(Object obj : pageRights){
                    OperationRight or = (OperationRight) obj;
                    if(code.toLowerCase().equals(or.getOperationKey().toLowerCase())){
                        return  1;
                    }
                }
            }
        } catch (Exception e) {
            throw new JspException(e);
        }
        return super.doStartTag();
    }

    public void setCode(String code) {
        this.code = code;
    }
}
